<template>
  <div class="app-container">
    <div class="filter-container">

      <el-form :model="listQuery" ref="filterForm">
        <el-row>
          <el-col :span="4">
            <el-form-item label="" class="postInfo-container-item" style="text-align: right" prop="search_type">
              <el-select v-model="listQuery.prize_type" placeholder="请选择" clearable class="filter-item">
                <el-option v-for="(key,item) in prizeType" :key="key" :label="item" :value="key"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
              查询
            </el-button>
          </el-col>
        </el-row>
      </el-form>

    </div>


    <el-table ref="dragTable" v-loading="listLoading" :data="list" row-key="id" fit highlight-current-row
              style="width: 100%;margin-top:30px;">
      <el-table-column align="center" label="会员信息">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height:50px"
            :src="scope.row.headimgurl"
            :preview-src-list="[scope.row.headimgurl]"
          >
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
          <el-button v-if="scope.row.nickname" type="danger" size="mini" @click="userDetail(scope.row.user_id)">{{ scope.row.nickname }}  </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="奖品名称">
        <template slot-scope="scope">
          {{ scope.row.prize_title }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="奖品类型">
        <template slot-scope="scope">
          {{prizeType[scope.row.prize_type]}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.prize_type==1">{{entityStatus[scope.row.entity_status]}}</span>
          <span v-if="scope.row.prize_type==2||scope.row.prize_type==4">{{isExchange[scope.row.is_exchange]}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="抽奖时间">
        <template slot-scope="scope">
          {{ scope.row.create_time}}
        </template>
      </el-table-column>
      <!--      <el-table-column align="center" label="抽奖地区">-->
      <!--        <template slot-scope="scope">-->
      <!--          {{ scope.row.create_time}}-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"/>
    <el-dialog :visible.sync="dialogVisibleUser" title="用户信息">
      <el-row :gutter="20">
        <el-col :span="16">
          <el-row :gutter="20">
            <el-col :span="12">
              <h2>基本信息</h2>
              <div class="user_info">微信昵称：{{userInfo.nickname}}</div>
              <div class="user_info">手机号：{{userInfo.mobile}}</div>
              <div class="user_info">地点：{{userInfo.user_address}}</div>
              <div class="user_info">OPENID：{{userInfo.openid}}</div>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="6">
              <h4 style="text-align: center">{{userInfo.total_cdkey_num}}</h4>
              <h4 style="text-align: center" >累计领红包次数</h4>
            </el-col>
            <el-col :span="6">
              <h4 style="text-align: center">￥{{userInfo.total_cdkey_money}}</h4>
              <h4 style="text-align: center" >累计领取红包金额</h4>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="8">
          <h2>抽奖次数</h2>
          <div class="user_info" v-for="item in userInfo.user_prize">
            {{item.prize_title}}：{{item.prize_num}}
          </div>
          <div class="user_info">累计抽奖次数：{{userInfo.total_draw_num}}</div>
        </el-col>
      </el-row>
    </el-dialog>

  </div>
</template>

<script>
  import waves from '@/directive/waves' // waves directive

  import Pagination from '@/components/Pagination'
  import { addRedPacket, getRedPacket, getRedPacketUrl } from '../../api/redPacket'
  import { getBigWheel, getUserPrizeLog } from '../../api/activity'
  import { getUserInfo } from '../../api/user'

  const prizeType = {
    1: '实物', 2: '虚拟', 3: '谢谢参与',4:'合成红包'
  }
  const entityStatus = {
    1: '待领取', 2: '待发放', 3: '已发放'
  }
  const isExchange = {
    1: '已领取', 2: '已兑换'
  }
  export default {
    components: { Pagination },
    directives: { waves },

    data() {
      return {
        prizeType,
        entityStatus,
        isExchange,
        activey: [],
        userInfo:{},
        list: [],
        total: 0,
        dialogVisibleUser: false,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          big_wheel_id: this.$route.query.id ?this.$route.query.id:''
        }
      }
    },
    created() {
      this.getList()
    },
    methods: {
      userDetail(user_id) {
        getUserInfo(user_id).then(res => {
          this.userInfo = res.data
          this.dialogVisibleUser = true
        })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      async getList() {
        this.listLoading = true
        const res = await getUserPrizeLog(this.listQuery)
        this.list = res.data.data
        this.total = res.data.total
        this.listLoading = false
      }
    }
  }
</script>

<style lang="scss" scoped>
  .app-container {
    .roles-table {
      margin-top: 30px;
    }

    .permission-tree {
      margin-bottom: 30px;
    }
  }
</style>
